package cse474_MultiThreadedHTTPServer.Environment;

public class CustomURI {
	private String uriText;
	private String command;
	private int fileSize;
	
	public CustomURI(String uriText) {
		setUriText(uriText);
		parseUri();
	}
//asdfasdf
	
	protected void parseUri()
	{
		int iterator = 0;
		String[] splitted = uriText.split(" ");
		
		while(splitted[iterator].compareTo("GET") != 0) {
			if(++iterator == splitted.length) {
				System.out.println("invalid");
				return;
			}
		}
		command = "GET";
		String str = splitted[++iterator].replace("/", "");
		
		try{
			fileSize = Integer.parseInt(str);
		}catch(NumberFormatException nfe)
		{
			fileSize = -1;
		}
		
		
		
		
	}
	
	private void setUriText(String uriText) {
		this.uriText = uriText;
	}

	public String getUriText() {
		return uriText;
	}
	
	public String getCommand() {
		return command;
	}
	
	public int getFileSize() {
		return fileSize;
	}
	
	public void setFileSize(int size) {
		this.fileSize = size;
	}
	
	public String toString(){
		return "URI\t: " + uriText + "\nCommand\t: " + command + "\nSize\t: " + fileSize;
	}
	
}
